import   m as mt
import mongo.DbUtil as pd
import  pymongo
if __name__=='__main__':
    headers = {
        'Referer': 'http://www.xicidaili.com/',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36'
    }
    url = 'http://www.xicidaili.com'

    iptable=mt.parse(mt.gethtml(url=url,headers=headers))

    #存储数据
    dbutils=pd.DbUtils('test','iptable')
  #  flag=dbutils.storage(data=iptable)
    # flag = dbutils.storage(data=data)
    old = {'address': '辽宁大连'}
    new = {'address': '浙江温州'}
    #flag = dbutils.update(old=old, new=new)
   # flag=dbutils.select(new,'',2,'')
    # field = {'port': 8080}
    # flag = dbutils.delete(field=field)
    # print("OP Result:", flag)
    # if flag:
    #     lst= list(flag[:])
    #     print(lst[0])
    # else:
    #      print("shibai")
    result = dbutils.select({'ipaddress': '112.114.93.175'}, ['ipaddress', 'address'], 3, [('port', pymongo.ASCENDING)])
    for item in result:
        print(item)
